/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package org.mahasen.client.gui;

import org.mahasen.authentication.ClientLoginData;
import org.mahasen.client.AuthenticationExceptionException;
import org.mahasen.client.Search;
import org.mahasen.exception.MahasenClientException;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.event.ActionEvent;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Hashtable;
import java.util.Map;
import java.util.Vector;

public class MultipleSearch extends javax.swing.JFrame {

    Hashtable<String, Vector<String>> searchQueries;
    ClientLoginData clientLoginData;

    /** Creates new form MultipleSearch */
    /**
     * @param clientLoginData
     */
    public MultipleSearch(ClientLoginData clientLoginData) {
        buttonGroup1 = new ButtonGroup();
        andRadioButton1 = new JRadioButton();
        orRadioButton2 = new JRadioButton();
        searchQueries = new Hashtable<String, Vector<String>>();
        initComponents();
        this.clientLoginData = clientLoginData;
        addedPropertTablePanel2.setVisible(false);

        buttonGroup1.add(andRadioButton1);
        buttonGroup1.add(orRadioButton2);
        andRadioButton1.setSelected(true);
        propertryBasedPanel.setVisible(true);
        rangeBasedPanel1.setVisible(false);
        tagBasedPanel1.setVisible(false);
        customPropertyPanel1.setVisible(false);
        customPropertyPanel2.setVisible(false);
        SearchResult.setVisible(false);
        SearchResult.setEditable(false);
    }

    /**
     * This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        searchPanel = new javax.swing.JPanel();
        propertryBasedPanel = new javax.swing.JPanel();
        jLabel10 = new javax.swing.JLabel();
        propertyValueTextField = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        propertyNameComboBox1 = new javax.swing.JComboBox();
        customPropertyPanel1 = new javax.swing.JPanel();
        jLabel13 = new javax.swing.JLabel();
        customPropertyTextField1 = new javax.swing.JTextField();
        searchTypeComboBox1 = new javax.swing.JComboBox();
        jLabel14 = new javax.swing.JLabel();
        rangeBasedPanel1 = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        initialValueTextField1 = new javax.swing.JTextField();
        lastValueTextField1 = new javax.swing.JTextField();
        propertyNameComboBox2 = new javax.swing.JComboBox();
        customPropertyPanel2 = new javax.swing.JPanel();
        jLabel16 = new javax.swing.JLabel();
        customPropertyTextField2 = new javax.swing.JTextField();
        andRadioButton1 = new javax.swing.JRadioButton();
        orRadioButton2 = new javax.swing.JRadioButton();
        jLabel1 = new javax.swing.JLabel();
        addSearchButton = new javax.swing.JButton();
        multipleSearchOkButton = new javax.swing.JButton();
        multipleSearchCancelButton = new javax.swing.JButton();
        jLabel11 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        SearchResult = new javax.swing.JTextArea();
        tagBasedPanel1 = new javax.swing.JPanel();
        jLabel18 = new javax.swing.JLabel();
        tagTextField1 = new javax.swing.JTextField();
        addedPropertTablePanel2 = new javax.swing.JPanel();
        jScrollPane4 = new javax.swing.JScrollPane();
        addedPropertyTable2 = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Advanced Search");

        propertryBasedPanel.setName("propertryBasedPanel"); // NOI18N

        jLabel10.setText("Property Value");

        propertyValueTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                propertyValueTextFieldActionPerformed(evt);
            }
        });

        jLabel12.setText("Property Name");

        propertyNameComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "File Name", "File Size", "Uploaded Date", "Custom Property" }));
        propertyNameComboBox1.setMinimumSize(new java.awt.Dimension(166, 25));
        propertyNameComboBox1.setOpaque(false);
        propertyNameComboBox1.setPreferredSize(new java.awt.Dimension(166, 25));
        propertyNameComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                propertyNameComboBox1ActionPerformed(evt);
            }
        });

        jLabel13.setText("Custom Property Name");

        customPropertyTextField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                customPropertyTextField1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout customPropertyPanel1Layout = new javax.swing.GroupLayout(customPropertyPanel1);
        customPropertyPanel1.setLayout(customPropertyPanel1Layout);
        customPropertyPanel1Layout.setHorizontalGroup(
            customPropertyPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(customPropertyPanel1Layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(jLabel13)
                .addGap(55, 55, 55)
                .addComponent(customPropertyTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        customPropertyPanel1Layout.setVerticalGroup(
            customPropertyPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(customPropertyPanel1Layout.createSequentialGroup()
                .addGap(17, 17, 17)
                .addComponent(jLabel13))
            .addGroup(customPropertyPanel1Layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(customPropertyTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        javax.swing.GroupLayout propertryBasedPanelLayout = new javax.swing.GroupLayout(propertryBasedPanel);
        propertryBasedPanel.setLayout(propertryBasedPanelLayout);
        propertryBasedPanelLayout.setHorizontalGroup(
            propertryBasedPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(propertryBasedPanelLayout.createSequentialGroup()
                .addGroup(propertryBasedPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(propertryBasedPanelLayout.createSequentialGroup()
                        .addGap(33, 33, 33)
                        .addComponent(jLabel12)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 106, Short.MAX_VALUE)
                        .addComponent(propertyNameComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(propertryBasedPanelLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(customPropertyPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(propertryBasedPanelLayout.createSequentialGroup()
                        .addGap(31, 31, 31)
                        .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(99, 99, 99)
                        .addComponent(propertyValueTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        propertryBasedPanelLayout.setVerticalGroup(
            propertryBasedPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(propertryBasedPanelLayout.createSequentialGroup()
                .addGap(15, 15, 15)
                .addGroup(propertryBasedPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(propertyNameComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(11, 11, 11)
                .addComponent(customPropertyPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(14, 14, 14)
                .addGroup(propertryBasedPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(propertyValueTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10)))
        );

        searchTypeComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Property Search", "Range Based Search", "Tag Search" }));
        searchTypeComboBox1.setInheritsPopupMenu(true);
        searchTypeComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                searchTypeComboBox1ActionPerformed(evt);
            }
        });

        jLabel14.setText("Search Type");

        rangeBasedPanel1.setName("Panel1"); // NOI18N

        jLabel8.setText("Property Name");

        jLabel9.setText("Initial Value");

        jLabel15.setText("Last Value");

        initialValueTextField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                initialValueTextField1ActionPerformed(evt);
            }
        });

        propertyNameComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "File Name", "File Size", "Uploaded Date", "Custom Property" }));
        propertyNameComboBox2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                propertyNameComboBox2ActionPerformed(evt);
            }
        });

        jLabel16.setText("Custom Property Name");

        customPropertyTextField2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                customPropertyTextField2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout customPropertyPanel2Layout = new javax.swing.GroupLayout(customPropertyPanel2);
        customPropertyPanel2.setLayout(customPropertyPanel2Layout);
        customPropertyPanel2Layout.setHorizontalGroup(
            customPropertyPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(customPropertyPanel2Layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(jLabel16)
                .addGap(56, 56, 56)
                .addComponent(customPropertyTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 248, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        customPropertyPanel2Layout.setVerticalGroup(
            customPropertyPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(customPropertyPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(customPropertyPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(customPropertyTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel16))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout rangeBasedPanel1Layout = new javax.swing.GroupLayout(rangeBasedPanel1);
        rangeBasedPanel1.setLayout(rangeBasedPanel1Layout);
        rangeBasedPanel1Layout.setHorizontalGroup(
            rangeBasedPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(rangeBasedPanel1Layout.createSequentialGroup()
                .addGap(32, 32, 32)
                .addComponent(jLabel8)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 104, Short.MAX_VALUE)
                .addComponent(propertyNameComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, 251, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(rangeBasedPanel1Layout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addComponent(customPropertyPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(rangeBasedPanel1Layout.createSequentialGroup()
                .addGap(33, 33, 33)
                .addGroup(rangeBasedPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel15)
                    .addComponent(jLabel9))
                .addGap(126, 126, 126)
                .addGroup(rangeBasedPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(lastValueTextField1)
                    .addComponent(initialValueTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 249, Short.MAX_VALUE))
                .addContainerGap())
        );
        rangeBasedPanel1Layout.setVerticalGroup(
            rangeBasedPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(rangeBasedPanel1Layout.createSequentialGroup()
                .addGroup(rangeBasedPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(rangeBasedPanel1Layout.createSequentialGroup()
                        .addGap(17, 17, 17)
                        .addComponent(jLabel8))
                    .addGroup(rangeBasedPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(propertyNameComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(9, 9, 9)
                .addComponent(customPropertyPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(rangeBasedPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(initialValueTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9))
                .addGap(18, 18, 18)
                .addGroup(rangeBasedPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lastValueTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel15))
                .addGap(15, 15, 15))
        );

        andRadioButton1.setText("AND");

        orRadioButton2.setText("OR");

        jLabel1.setText("Search with :");

        addSearchButton.setText("Add for Searching");
        addSearchButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addSearchButtonActionPerformed(evt);
            }
        });

        multipleSearchOkButton.setText("Search");
        multipleSearchOkButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                multipleSearchOkButtonActionPerformed(evt);
            }
        });

        multipleSearchCancelButton.setText("Cancel");
        multipleSearchCancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                multipleSearchCancelButtonActionPerformed(evt);
            }
        });

        jLabel11.setText("Search results :");

        SearchResult.setColumns(20);
        SearchResult.setRows(5);
        jScrollPane1.setViewportView(SearchResult);

        tagBasedPanel1.setName("Panel1"); // NOI18N

        jLabel18.setText("Tags to search :");

        tagTextField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tagTextField1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout tagBasedPanel1Layout = new javax.swing.GroupLayout(tagBasedPanel1);
        tagBasedPanel1.setLayout(tagBasedPanel1Layout);
        tagBasedPanel1Layout.setHorizontalGroup(
            tagBasedPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tagBasedPanel1Layout.createSequentialGroup()
                .addGap(33, 33, 33)
                .addComponent(jLabel18, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 70, Short.MAX_VALUE)
                .addComponent(tagTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 251, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        tagBasedPanel1Layout.setVerticalGroup(
            tagBasedPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tagBasedPanel1Layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(tagBasedPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel18)
                    .addComponent(tagTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        addedPropertyTable2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Property Name", "Property Value"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane4.setViewportView(addedPropertyTable2);

        javax.swing.GroupLayout addedPropertTablePanel2Layout = new javax.swing.GroupLayout(addedPropertTablePanel2);
        addedPropertTablePanel2.setLayout(addedPropertTablePanel2Layout);
        addedPropertTablePanel2Layout.setHorizontalGroup(
            addedPropertTablePanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(addedPropertTablePanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 363, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(20, Short.MAX_VALUE))
        );
        addedPropertTablePanel2Layout.setVerticalGroup(
            addedPropertTablePanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(addedPropertTablePanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout searchPanelLayout = new javax.swing.GroupLayout(searchPanel);
        searchPanel.setLayout(searchPanelLayout);
        searchPanelLayout.setHorizontalGroup(
            searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(searchPanelLayout.createSequentialGroup()
                .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(searchPanelLayout.createSequentialGroup()
                        .addGap(32, 32, 32)
                        .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel14, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1))
                        .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(searchPanelLayout.createSequentialGroup()
                                .addGap(75, 75, 75)
                                .addComponent(andRadioButton1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(orRadioButton2))
                            .addGroup(searchPanelLayout.createSequentialGroup()
                                .addGap(52, 52, 52)
                                .addComponent(searchTypeComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 251, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addComponent(propertryBasedPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(tagBasedPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(rangeBasedPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(searchPanelLayout.createSequentialGroup()
                        .addGap(51, 51, 51)
                        .addComponent(addedPropertTablePanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(searchPanelLayout.createSequentialGroup()
                        .addGap(25, 25, 25)
                        .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(searchPanelLayout.createSequentialGroup()
                                .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(47, 47, 47)
                                .addComponent(multipleSearchOkButton, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(48, 48, 48)
                                .addComponent(multipleSearchCancelButton, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 449, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(addSearchButton, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        searchPanelLayout.setVerticalGroup(
            searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(searchPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(orRadioButton2)
                    .addComponent(jLabel1)
                    .addComponent(andRadioButton1))
                .addGap(19, 19, 19)
                .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel14, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(searchTypeComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(propertryBasedPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(rangeBasedPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 167, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tagBasedPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(addedPropertTablePanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(addSearchButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(multipleSearchCancelButton)
                        .addComponent(multipleSearchOkButton))
                    .addComponent(jLabel11))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(searchPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(searchPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-512)/2, (screenSize.height-595)/2, 512, 595);
    }// </editor-fold>//GEN-END:initComponents

    private void searchTypeComboBox1ActionPerformed(ActionEvent evt) {//GEN-FIRST:event_searchTypeComboBox1ActionPerformed
        if (searchTypeComboBox1.getSelectedIndex() == 0) {
            propertryBasedPanel.setVisible(true);
            rangeBasedPanel1.setVisible(false);
            tagBasedPanel1.setVisible(false);
        } else if (searchTypeComboBox1.getSelectedIndex() == 1) {
            propertryBasedPanel.setVisible(false);
            rangeBasedPanel1.setVisible(true);
            tagBasedPanel1.setVisible(false);
            //customPropertyPanel2.setVisible(false);
        } else if (searchTypeComboBox1.getSelectedIndex() == 2) {
            SearchResult.setText("");
            propertryBasedPanel.setVisible(false);
            tagBasedPanel1.setVisible(true);
            rangeBasedPanel1.setVisible(false);
        }


        //To change body of created methods use File | Settings | File Templates.
    }//GEN-LAST:event_searchTypeComboBox1ActionPerformed

    private void customPropertyTextField1ActionPerformed(ActionEvent evt) {
        //To change body of created methods use File | Settings | File Templates.
    }

    private void propertyValueTextFieldActionPerformed(ActionEvent evt) {//GEN-FIRST:event_customPropertyTextField1ActionPerformed
        //To change body of created methods use File | Settings | File Templates.
    }//GEN-LAST:event_customPropertyTextField1ActionPerformed

    private void propertyNameComboBox1ActionPerformed(ActionEvent evt) {//GEN-FIRST:event_propertyNameComboBox1ActionPerformed

        if (propertyNameComboBox1.getSelectedIndex() == 3) {
            customPropertyPanel1.setVisible(true);
        } else {
            customPropertyPanel1.setVisible(false);
        }


        //To change body of created methods use File | Settings | File Templates.
    }//GEN-LAST:event_propertyNameComboBox1ActionPerformed

//GEN-FIRST:event_propertyValueTextFieldActionPerformed
//GEN-LAST:event_propertyValueTextFieldActionPerformed
//GEN-FIRST:event_jComboBox2ActionPerformed
//GEN-LAST:event_jComboBox2ActionPerformed
    private void initialValueTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_initialValueTextField1ActionPerformed
// TODO add your handling code here:
    }//GEN-LAST:event_initialValueTextField1ActionPerformed

    private void propertyNameComboBox2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_propertyNameComboBox2ActionPerformed

        if (propertyNameComboBox2.getSelectedIndex() == 3) {
            customPropertyPanel2.setVisible(true);
        } else {
            customPropertyPanel2.setVisible(false);
        }
        // TODO add your handling code here:
    }//GEN-LAST:event_propertyNameComboBox2ActionPerformed

    private void customPropertyTextField2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_customPropertyTextField2ActionPerformed
// TODO add your handling code here:
    }//GEN-LAST:event_customPropertyTextField2ActionPerformed

    private void multipleSearchCancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_multipleSearchCancelButtonActionPerformed

        this.dispose();// TODO add your handling code here:
    }//GEN-LAST:event_multipleSearchCancelButtonActionPerformed

    private void addSearchButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addSearchButtonActionPerformed


        String propertyName = null;
        String propertyValue = null;
        if (searchTypeComboBox1.getSelectedIndex() == 0) {
            if (propertyNameComboBox1.getSelectedIndex() == 0) {
                propertyName = "fileName";
                propertyValue = propertyValueTextField.getText();
            } else if (propertyNameComboBox1.getSelectedIndex() == 1) {
                propertyName = "fileSize(MB)";
                propertyValue = propertyValueTextField.getText();

                if(propertyValue.contains(".")){
                    propertyValue = propertyValue.substring(0, propertyValue.indexOf("."));
                }
                if(!propertyValue.equals("")) {
                    try{
                        int value = Integer.valueOf(propertyValue);
                    } catch (Exception e) {
                        JOptionPane.showMessageDialog(this, "Invalid argument" , "Wrong argument", JOptionPane.ERROR_MESSAGE);
                        return;
                    }
                }
            } else if (propertyNameComboBox1.getSelectedIndex() == 2) {
                propertyName = "uploadedDate";
                propertyValue = propertyValueTextField.getText().replace(".", "");
                if(!propertyValue.equals("")) {
                    try{
                        int value = Integer.valueOf(propertyValue);
                    } catch (Exception e) {
                        JOptionPane.showMessageDialog(this, "Invalid argument" , "Wrong argument", JOptionPane.ERROR_MESSAGE);
                        return;
                    }
                }
            } else if (propertyNameComboBox1.getSelectedIndex() == 3) {
                propertyName = customPropertyTextField1.getText();
                propertyValue = propertyValueTextField.getText();
            }

            if (propertyName != null && propertyValue != null
                    && !propertyName.equals("") && !propertyValue.equals("")) {
                //if (searchQueries.contains(propertyName)) {
                if (searchQueries.keySet().contains(propertyName)) {
                    searchQueries.get(propertyName).add(propertyValue);
                } else {
                    Vector<String> valuesVector = new Vector<String>();
                    valuesVector.add(propertyValue);
                    searchQueries.put(propertyName, valuesVector);
                }
            } else {
                JOptionPane.showMessageDialog(this, "Search Queries are Empty");
            }

            propertyValueTextField.setText("");
            customPropertyTextField1.setText("");

        } else if (searchTypeComboBox1.getSelectedIndex() == 1) {
            String initialValue = null;
            String lastValue = null;
            if (propertyNameComboBox2.getSelectedIndex() == 0) {
                propertyName = "fileName";
                initialValue = initialValueTextField1.getText();
                lastValue = lastValueTextField1.getText();
            } else if (propertyNameComboBox2.getSelectedIndex() == 1) {
                propertyName = "fileSize(MB)";

                initialValue = initialValueTextField1.getText();
                if(initialValue.contains(".")){
                    initialValue = initialValue.substring(0, initialValue.indexOf("."));
                }
                if(!initialValue.equals("")) {
                    try{
                        int value = Integer.valueOf(initialValue);
                    } catch (Exception e) {
                        JOptionPane.showMessageDialog(this, "Invalid argument" , "Wrong argument", JOptionPane.ERROR_MESSAGE);
                        return;
                    }
                }

                lastValue = lastValueTextField1.getText();
                if(lastValue.contains(".")){
                    lastValue = lastValue.substring(0, lastValue.indexOf("."));
                }
                if(!lastValue.equals("")) {
                    try{
                        int value = Integer.valueOf(lastValue);
                    } catch (Exception e) {
                        JOptionPane.showMessageDialog(this, "Invalid argument" , "Wrong argument", JOptionPane.ERROR_MESSAGE);
                        return;
                    }
                }

                if (Integer.valueOf(initialValue) > Integer.valueOf(lastValue)) {
                    JOptionPane.showMessageDialog(this, "Initial value should be smaller than the last value");
                    initialValueTextField1.setText("");
                    lastValueTextField1.setText("");
                    return;
                }
            } else if (propertyNameComboBox2.getSelectedIndex() == 2) {
                propertyName = "uploadedDate";
                initialValue = initialValueTextField1.getText().replace(".", "");
                if(!initialValue.equals("")) {
                    try{
                        int value = Integer.valueOf(initialValue);
                    } catch (Exception e) {
                        JOptionPane.showMessageDialog(this, "Invalid argument" , "Wrong argument", JOptionPane.ERROR_MESSAGE);
                        return;
                    }
                }

                lastValue = lastValueTextField1.getText().replace(".", "");
                if(!lastValue.equals("")) {
                    try{
                        int value = Integer.valueOf(lastValue);
                    } catch (Exception e) {
                        JOptionPane.showMessageDialog(this, "Invalid argument" , "Wrong argument", JOptionPane.ERROR_MESSAGE);
                        return;
                    }
                }

                if (Integer.valueOf(initialValue) > Integer.valueOf(lastValue)) {
                    JOptionPane.showMessageDialog(this, "Initial value should be smaller than the last value");
                    initialValueTextField1.setText("");
                    lastValueTextField1.setText("");
                    return;
                }
            } else {
                customPropertyPanel2.setVisible(true);
                propertyName = customPropertyTextField2.getText();
                initialValue = initialValueTextField1.getText();
                lastValue = lastValueTextField1.getText();
            }
            if (propertyName != null && initialValue != null && lastValue != null
                    && !propertyName.equals("") && !initialValue.equals("") && !lastValue.equals("")) {
                if (searchQueries.keySet().contains(propertyName)) {
                    searchQueries.get(propertyName).add(initialValue.concat(",").concat(lastValue));
                } else {
                    Vector<String> valuesVector = new Vector<String>();
                    valuesVector.add(initialValue.concat(",").concat(lastValue));
                    searchQueries.put(propertyName, valuesVector);
                }
                //searchQueries.put(propertyName, initialValue.concat(",").concat(lastValue));
            } else {
                JOptionPane.showMessageDialog(this, "Search Queries are Empty");
            }

            initialValueTextField1.setText("");
            lastValueTextField1.setText("");
            customPropertyTextField2.setText("");
        } else {
            String tag = tagTextField1.getText();
            if (tag != null && !tag.equals("")) {
                //if (searchQueries.contains("tags")) {
                if (searchQueries.keySet().contains("tags")) {
                    searchQueries.get("tags").add(tag);
                } else {
                    Vector<String> valuesVector = new Vector<String>();
                    valuesVector.add(tag);
                    searchQueries.put("tags", valuesVector);
                }
            } else {
                JOptionPane.showMessageDialog(this, "Search Queries are Empty");
            }

            tagTextField1.setText("");
        }

        if (!searchQueries.isEmpty()) {
            addedPropertTablePanel2.setVisible(true);
            ((DefaultTableModel) addedPropertyTable2.getModel()).setNumRows(searchQueries.size());
            int i =0;
                for (Map.Entry<String, Vector<String>> entry : searchQueries.entrySet()) {
                    addedPropertyTable2.getModel().setValueAt(entry.getKey(), i, 0);
                    addedPropertyTable2.getModel().setValueAt(entry.getValue(), i, 1);
                    i++;
            }
        }
        else{
            addedPropertTablePanel2.setVisible(false);
        }
        // TODO add your handling code here:
    }//GEN-LAST:event_addSearchButtonActionPerformed

    private void multipleSearchOkButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_multipleSearchOkButtonActionPerformed

        Search search = new Search(clientLoginData);
        SearchResult.setText("");

        String propertyName = null;
        String propertyValue = null;
        try {
            if (searchTypeComboBox1.getSelectedIndex() == 0) {
                if (propertyNameComboBox1.getSelectedIndex() == 0) {
                    propertyName = "fileName";
                    propertyValue = propertyValueTextField.getText();
                } else if (propertyNameComboBox1.getSelectedIndex() == 1) {
                    propertyName = "fileSize(MB)";
                    propertyValue = propertyValueTextField.getText();
                    if(propertyValue.contains(".")){
                        propertyValue = propertyValue.substring(0, propertyValue.indexOf("."));
                    }
                    if(!propertyValue.equals("")) {
                        try{
                            int value = Integer.valueOf(propertyValue);
                        } catch (Exception e) {
                            JOptionPane.showMessageDialog(this, "Invalid argument" , "Wrong argument", JOptionPane.ERROR_MESSAGE);
                            return;
                        }
                    }

                } else if (propertyNameComboBox1.getSelectedIndex() == 2) {
                    propertyName = "uploadedDate";
                    propertyValue = propertyValueTextField.getText().replace(".", "");
                    if(!propertyValue.equals("")) {
                        try{
                            int value = Integer.valueOf(propertyValue);
                        } catch (Exception e) {
                            JOptionPane.showMessageDialog(this, "Invalid argument" , "Wrong argument", JOptionPane.ERROR_MESSAGE);
                            return;
                        }
                    }
                } else if (propertyNameComboBox1.getSelectedIndex() == 3) {
                    propertyName = customPropertyTextField1.getText();
                    propertyValue = propertyValueTextField.getText();
                }

                if (propertyName != null && propertyValue != null
                        && !propertyName.equals("") && !propertyValue.equals("")) {
                    //searchQueries.put(propertyName, propertyValue);
                    //if (searchQueries.contains(propertyName)) {
                    if (searchQueries.keySet().contains(propertyName)) {
                        searchQueries.get(propertyName).add(propertyValue);
                    } else {
                        Vector<String> valuesVector = new Vector<String>();
                        valuesVector.add(propertyValue);
                        searchQueries.put(propertyName, valuesVector);
                    }
                }
                if (!searchQueries.isEmpty()) {
                    if (andRadioButton1.isSelected()) {
                        String result = search.multipleAndSearch(searchQueries);
                        searchQueries = new Hashtable<String, Vector<String>>();
                        if (result.equals("")) {
                            JOptionPane.showMessageDialog(this, "No result found");
                            SearchResult.setText("No result found");
                        } else {
                            SearchResult.setText(result.replace(", ", "\n"));
                            SearchResult.setVisible(true);
                        }
                    } else {

                        String result = search.multipleOrSearch(searchQueries);
                        searchQueries = new Hashtable<String, Vector<String>>();
                        if (result.equals("")) {
                            JOptionPane.showMessageDialog(this, "No result found");
                            SearchResult.setText("No result found");
                        } else {
                            SearchResult.setText(result.replace(", ", "\n"));
                            SearchResult.setVisible(true);
                        }

                    }
                } else {
                    JOptionPane.showMessageDialog(this, "Search Queries are Empty");
                }
                propertyValueTextField.setText("");
                customPropertyTextField1.setText("");

            } else if (searchTypeComboBox1.getSelectedIndex() == 1) {
                String initialValue = null;
                String lastValue = null;
                if (propertyNameComboBox2.getSelectedIndex() == 0) {
                    propertyName = "fileName";
                    initialValue = initialValueTextField1.getText();
                    lastValue = lastValueTextField1.getText();
                } else if (propertyNameComboBox2.getSelectedIndex() == 1) {
                    propertyName = "fileSize(MB)";
                    initialValue = initialValueTextField1.getText();
                    if(initialValue.contains(".")){
                        initialValue = initialValue.substring(0, initialValue.indexOf("."));
                    }
                    if(!initialValue.equals("")) {
                        try{
                            int value = Integer.valueOf(initialValue);
                        } catch (Exception e) {
                            JOptionPane.showMessageDialog(this, "Invalid argument" , "Wrong argument", JOptionPane.ERROR_MESSAGE);
                            return;
                        }
                    }
                    lastValue = lastValueTextField1.getText();
                    if(lastValue.contains(".")){
                        lastValue = lastValue.substring(0, lastValue.indexOf("."));
                    }
                    if(!lastValue.equals("")) {
                        try{
                            int value = Integer.valueOf(lastValue);
                        } catch (Exception e) {
                            JOptionPane.showMessageDialog(this, "Invalid argument" , "Wrong argument", JOptionPane.ERROR_MESSAGE);
                            return;
                        }
                    }
                    if (Integer.valueOf(initialValue) > Integer.valueOf(lastValue)) {
                        JOptionPane.showMessageDialog(this, "Initial value should be smaller than the last value");
                        initialValueTextField1.setText("");
                        lastValueTextField1.setText("");
                        return;
                    }
                } else if (propertyNameComboBox2.getSelectedIndex() == 2) {
                    propertyName = "uploadedDate";
                    initialValue = initialValueTextField1.getText().replace(".", "");
                    if(!initialValue.equals("")) {
                        try{
                            int value = Integer.valueOf(initialValue);
                        } catch (Exception e) {
                            JOptionPane.showMessageDialog(this, "Invalid argument" , "Wrong argument", JOptionPane.ERROR_MESSAGE);
                            return;
                        }
                    }
                    lastValue = lastValueTextField1.getText().replace(".", "");
                    if(!lastValue.equals("")) {
                        try{
                            int value = Integer.valueOf(lastValue);
                        } catch (Exception e) {
                            JOptionPane.showMessageDialog(this, "Invalid argument" , "Wrong argument", JOptionPane.ERROR_MESSAGE);
                            return;
                        }
                    }

                    lastValue = lastValueTextField1.getText().replace(".", "");
                    if (Integer.valueOf(initialValue) > Integer.valueOf(lastValue)) {
                        JOptionPane.showMessageDialog(this, "Initial value should be smaller than the last value");
                        initialValueTextField1.setText("");
                        lastValueTextField1.setText("");
                        return;
                    }
                } else {
                    customPropertyPanel2.setVisible(true);
                    propertyName = customPropertyTextField2.getText();
                    initialValue = initialValueTextField1.getText();
                    lastValue = lastValueTextField1.getText();
                }

                if (propertyName != null && initialValue != null && lastValue != null
                        && !propertyName.equals("") && !initialValue.equals("") && !lastValue.equals("")) {
                    //if (searchQueries.contains(propertyName)) {
                    if (searchQueries.keySet().contains(propertyName)) {
                        searchQueries.get(propertyName).add(initialValue.concat(",").concat(lastValue));
                    } else {
                        Vector<String> valuesVector = new Vector<String>();
                        valuesVector.add(initialValue.concat(",").concat(lastValue));
                        searchQueries.put(propertyName, valuesVector);
                    }
                }

                if (!searchQueries.isEmpty()) {
                    if (andRadioButton1.isSelected()) {

                        String result = search.multipleAndSearch(searchQueries);
                        searchQueries = new Hashtable<String, Vector<String>>();
                        if (result.equals("")) {
                            JOptionPane.showMessageDialog(this, "No result found");
                            SearchResult.setText("No result found");
                        } else {
                            SearchResult.setText(result.replace(", ", "\n"));
                            SearchResult.setVisible(true);
                        }

                    } else {

                        String result = search.multipleOrSearch(searchQueries);
                        searchQueries = new Hashtable<String, Vector<String>>();
                        if (result.equals("")) {
                            JOptionPane.showMessageDialog(this, "No result found");
                            SearchResult.setText("No result found");
                        } else {
                            SearchResult.setText(result.replace(", ", "\n"));
                            SearchResult.setVisible(true);
                        }

                    }
                } else {
                    JOptionPane.showMessageDialog(this, "Search Queries are Empty");
                }
                initialValueTextField1.setText("");
                lastValueTextField1.setText("");
                customPropertyTextField2.setText("");
            } else {

                String tag = tagTextField1.getText();
                if (tag != null && !tag.equals("")) {
                    //if (searchQueries.contains("tags")) {
                    if (searchQueries.keySet().contains("tags")) {
                        searchQueries.get("tags").add(tag);
                    } else {
                        Vector<String> valuesVector = new Vector<String>();
                        valuesVector.add(tag);
                        searchQueries.put("tags", valuesVector);
                    }
                }

                if (!searchQueries.isEmpty()) {
                    if (andRadioButton1.isSelected()) {

                        String result = search.multipleAndSearch(searchQueries);
                        searchQueries = new Hashtable<String, Vector<String>>();
                        if (result.equals("")) {
                            JOptionPane.showMessageDialog(this, "No result found");
                            SearchResult.setText("No result found");
                        } else {
                            SearchResult.setText(result.replace(", ", "\n"));
                            SearchResult.setVisible(true);
                        }

                    } else {

                        String result = search.multipleOrSearch(searchQueries);
                        searchQueries = new Hashtable<String, Vector<String>>();
                        if (result.equals("")) {
                            JOptionPane.showMessageDialog(this, "No result found");
                            SearchResult.setText("No result found");
                        } else {
                            SearchResult.setText(result.replace(", ", "\n"));
                            SearchResult.setVisible(true);
                        }

                    }
                } else {
                    JOptionPane.showMessageDialog(this, "Search Queries are Empty");
                }


            }
        } catch (IOException ex) {
            JOptionPane.showMessageDialog(this, "Error Occured In network while "
                    + "Searching. Please Try again", "Search Error", JOptionPane.ERROR_MESSAGE);
        } catch (AuthenticationExceptionException e) {
            JOptionPane.showMessageDialog(this, "Error Occured In Authenticating "
                    + "Searching. Please Try again", "Search Error", JOptionPane.ERROR_MESSAGE);
        } catch (URISyntaxException e) {
            JOptionPane.showMessageDialog(this, "Error Occured while "
                    + "Searching. Please Try again", "Search Error", JOptionPane.ERROR_MESSAGE);
        } catch (MahasenClientException e) {
            JOptionPane.showMessageDialog(this, e.getMessage());
            SearchResult.setText("No result found");
        }
        // TODO add your handling code here:
    }//GEN-LAST:event_multipleSearchOkButtonActionPerformed

    private void tagTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tagTextField1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tagTextField1ActionPerformed
    /**
     * @param args the command line arguments
     */
//    public static void main(String args[]) {
//        java.awt.EventQueue.invokeLater(new Runnable() {
//            public void run() {
//                new MultipleSearch().setVisible(true);
//            }
//        });
//    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextArea SearchResult;
    private javax.swing.JButton addSearchButton;
    private javax.swing.JPanel addedPropertTablePanel2;
    private javax.swing.JTable addedPropertyTable2;
    private javax.swing.JRadioButton andRadioButton1;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JPanel customPropertyPanel1;
    private javax.swing.JPanel customPropertyPanel2;
    private javax.swing.JTextField customPropertyTextField1;
    private javax.swing.JTextField customPropertyTextField2;
    private javax.swing.JTextField initialValueTextField1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JTextField lastValueTextField1;
    private javax.swing.JButton multipleSearchCancelButton;
    private javax.swing.JButton multipleSearchOkButton;
    private javax.swing.JRadioButton orRadioButton2;
    private javax.swing.JPanel propertryBasedPanel;
    private javax.swing.JComboBox propertyNameComboBox1;
    private javax.swing.JComboBox propertyNameComboBox2;
    private javax.swing.JTextField propertyValueTextField;
    private javax.swing.JPanel rangeBasedPanel1;
    private javax.swing.JPanel searchPanel;
    private javax.swing.JComboBox searchTypeComboBox1;
    private javax.swing.JPanel tagBasedPanel1;
    private javax.swing.JTextField tagTextField1;
    // End of variables declaration//GEN-END:variables
}
